//==============================================================================
// militaryUpgradeMordor
//==============================================================================
rule militaryUpgradeMordor
   minInterval 31
   active
   runImmediately
{
	if(cMyCulture != cCultureAtlantean)
	{
      		xsDisableSelf();
		return;
	}
		
   	//Must be setup for resources before we do any of this.
	if ( (kbSetupForResource(kbBaseGetMainID(cMyID), cResourceWood, 25.0, 400) == false) ||
	     (kbSetupForResource(kbBaseGetMainID(cMyID), cResourceFood, 25.0, 400) == false) )
		return;

	//Define Armory Progression (all civs)

	int apid = aiPlanCreate("armoryUpgradeMordor",cPlanProgression);
   	if (apid >= 0)
   	{ 
      		aiPlanSetVariableBool(apid, cProgressionPlanRunInParallel, 0, true);
      		aiPlanSetDesiredPriority(apid, 75);
		aiPlanSetEscrowID(apid, cMilitaryEscrowID);
      		aiPlanSetBaseID(apid, kbBaseGetMainID(cMyID));
      
		aiPlanSetNumberVariableValues(apid, cProgressionPlanGoalTechID, 9, true);

		if (aiGetWorldDifficulty() == cDifficultyNightmare)
			aiPlanSetNumberVariableValues(apid, cProgressionPlanGoalTechID, 12, true);

		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 0, cTechLeatherArmor);
		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 1, cTechWoodenShields);
		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 2, cTechBow);
		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 3, cTechSword);
		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 4, cTechWargHides);
		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 5, cTechQuiver);
		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 6, cTechChainMail);
		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 7, cTechShields);
		aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 8, cTechHelmets);
      
		if (aiGetWorldDifficulty() == cDifficultyNightmare)
		{
			aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 9, cTechHalberd);
			aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 10, cTechChainMace);
			aiPlanSetVariableInt(apid, cProgressionPlanGoalTechID, 11, cTechLongSword);
		}

		aiPlanSetActive(apid);
	}
	else
		aiPlanDestroy(apid);

	//Define Foundry Progression (all civs)

	int fpid = aiPlanCreate("foundryUpgrademORDOR",cPlanProgression);
   	if (fpid >= 0)
   	{ 
      		aiPlanSetVariableBool(fpid, cProgressionPlanRunInParallel, 0, true);
      		aiPlanSetDesiredPriority(fpid, 75);
		aiPlanSetEscrowID(fpid, cMilitaryEscrowID);
      		aiPlanSetBaseID(fpid, kbBaseGetMainID(cMyID));
      
		aiPlanSetNumberVariableValues(fpid, cProgressionPlanGoalTechID, 5, true);

		if (aiGetWorldDifficulty() == cDifficultyNightmare)
			aiPlanSetNumberVariableValues(fpid, cProgressionPlanGoalTechID, 7, true);

		aiPlanSetVariableInt(fpid, cProgressionPlanGoalTechID, 0, cTechCopper);
		aiPlanSetVariableInt(fpid, cProgressionPlanGoalTechID, 1, cTechBronzeAlloy);
		aiPlanSetVariableInt(fpid, cProgressionPlanGoalTechID, 2, cTechMetalCasting);
		aiPlanSetVariableInt(fpid, cProgressionPlanGoalTechID, 3, cTechMetalHardening);
		aiPlanSetVariableInt(fpid, cProgressionPlanGoalTechID, 4, cTechAnnaAngron);
      
		if (aiGetWorldDifficulty() == cDifficultyNightmare)
		{
			aiPlanSetVariableInt(fpid, cProgressionPlanGoalTechID, 5, cTechAnnealing);
			aiPlanSetVariableInt(fpid, cProgressionPlanGoalTechID, 6, cTechMeteoricIron);
		}

		aiPlanSetActive(fpid);
	}
	else
		aiPlanDestroy(fpid);

   	//Define Military Progression Plan
   	int pid=aiPlanCreate("militaryUpgradeMordor", cPlanProgression);
   	if (pid >= 0)
   	{ 
      		aiPlanSetVariableBool(pid, cProgressionPlanRunInParallel, 0, true);
      		aiPlanSetDesiredPriority(pid, 75);
		aiPlanSetEscrowID(pid, cMilitaryEscrowID);
      		aiPlanSetBaseID(pid, kbBaseGetMainID(cMyID));
      
		aiPlanSetNumberVariableValues(pid, cProgressionPlanGoalTechID, 6, true);

		if (aiGetWorldDifficulty() == cDifficultyNightmare)
			aiPlanSetNumberVariableValues(pid, cProgressionPlanGoalTechID, 9, true);
         			
        		aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 0, cTechMediumCavalry);
         		aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 1, cTechMediumInfantry);
         		aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 2, cTechMediumArchers);
         		aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 3, cTechHeavyCavalry);
         		aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 4, cTechHeavyInfantry);
         		aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 5, cTechHeavyArchers);

		if (aiGetWorldDifficulty() == cDifficultyNightmare)
		{
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 6, cTechChampionCavalry);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 7, cTechChampionInfantry);
         			aiPlanSetVariableInt(pid, cProgressionPlanGoalTechID, 8, cTechChampionArchers);
		}

		aiPlanSetActive(pid);
	}
	else
		aiPlanDestroy(pid);


      	xsDisableSelf();
}

